package com.noahplat.person.controller;

import com.noahplat.common.utils.Result;
import com.noahplat.person.pojo.Disease;
import com.noahplat.person.service.DiseaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

/**
 * @ClassName: Disease
 * @Description: 疾病枚举接口
 * @Author 李景星
 * @Date 2021/3/5
 * @Version 1.0
 */
@RestController
@RequestMapping("/api/disease")
@Validated
public class DiseaseController {

    @Autowired
    private DiseaseService diseaseService;

    /**
     * 获取所有疾病字典
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:DiseaseController:getAllDisease')")
    @GetMapping("/getAllDisease")
    public Result getAllDisease(){
        return diseaseService.getAllDisease();
    }

    /**
     * 添加疾病字典
     * @param disease
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:DiseaseController:addDisease')")
    @PostMapping("/addDisease")
    public Result addDisease(@RequestBody Disease disease){
        return diseaseService.addDisease(disease);
    }

    /**
     * 分页获取疾病字典
     * @param page
     * @param limit
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:DiseaseController:getAdminDisease')")
    @GetMapping("/getAdminDisease")
    public Result getAdminDisease(@RequestParam(defaultValue = "1")Integer page,@RequestParam(defaultValue = "10")Integer limit){
        return diseaseService.getAdminDisease(page, limit);
    }

    /**
     * 获取疾病字典详细信息
     * @param id
     * @return
     */
    @PreAuthorize("hasAuthority('noahplat-service-person:DiseaseController:getDiseaseById')")
    @GetMapping("/getDiseaseById")
    public Result getDiseaseById(@NotNull(message = "ID不能为空 ") @Min(value = 1, message = "Id不能为空")Long id){
        return diseaseService.getDiseaseById(id);
    }
}
